<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: LanguageCheck.php 361 2010-02-03 08:08:44Z steen.rabol@gmail.com $
 *
 */
Prado::using('Application.Common.Data.PortalLanguageStringRecord');
class LanguageCheck extends PortalAdminPage
{
	public static function ToolMenuName()
	{
		return Prado::localize('Check language');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->setAdminPageTitle("Check language");

		if(!$this->IsPostBack)
		{
			$dr = $this->DataAccess->createCommand("select culture,name from tbllanguages where active=1")->query();
			$rows = $dr->readAll();
			$this->dlSourceLanglist->PromptText	= Prado::localize("Select");
			$this->dlSourceLanglist->PromptValue	= 0;
			$this->dlSourceLanglist->DataSource	= $rows;
			$this->dlSourceLanglist->dataBind();

			$this->dlDestLanglist->PromptText	= Prado::localize("Select");
			$this->dlDestLanglist->PromptValue	= 0;
			$this->dlDestLanglist->DataSource	= $rows;
			$this->dlDestLanglist->dataBind();
		}
	}

	public function CheckLanguage()
	{
		if($this->IsValid)
		{
			$source	= $this->dlSourceLanglist->SelectedValue;
			$dest	= $this->dlDestLanglist->SelectedValue;
			$dr		= PortalLanguageStringRecord::finder()->findAll('culture = ?', $source);
			$res	= array();

			if($dr)
			{
				$cnt = 0;
				foreach($dr as $r)
				{
					$destString	= PortalLanguageStringRecord::finder()->find('culture = ? AND fromvalue = ? and lkey = ?', $dest, trim($r->fromvalue),$r->lkey);
					if($destString === null)
					{
						$lrec	= new PortalLanguageStringRecord();
						$lrec->culture		= $dest;
						$lrec->lkey			= $r->lkey;
						$lrec->fromvalue	= $r->fromvalue;
						$lrec->tovalue		= $r->fromvalue;
						$lrec->save();

						$res[] = array('fromvalue'  => $r->fromvalue, 'tovalue' => $r->fromvalue);
					}
					$cnt++;
				}
			}

			$this->pnlLangCheckStart->Visible = false;
			$this->pnlLangCheckResult->Visible = true;

			$this->Repeater->DataSource	= $res;
			$this->Repeater->dataBind();

			if(count($res) > 0)
			{
				$this->lblLangCheckTxt->Text = Prado::localize('The folowing strings where created in the destination language');
			}
			else
			{
				$this->lblLangCheckTxt->Text = Prado::localize('No strings where added to the desination language');
			}
		}
	}
}
?>